﻿<UserControl x:Class="CAION2.Views.RecepturePage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:viewModels="clr-namespace:CAION2.ViewModels"
             xmlns:resources="clr-namespace:CAION2.Properties"
             xmlns:helpers="clr-namespace:CAION2.Helpers"
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit">

    <UserControl.DataContext>
        <viewModels:ReceptureTreeViewModel/>
    </UserControl.DataContext>
    
    <UserControl.Resources>

        <viewModels:ItemTypeColorConverter x:Key="ItemTypeColor" />
        <viewModels:BooleanToBitConverter x:Key="BooleanToBit" />
        <helpers:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

        <DrawingImage x:Key="RecipeLevelIcon">
            <DrawingImage.Drawing>
                <GeometryDrawing Geometry="M 41,35L 41,57L 35,57L 35,35L 41,35 Z M 33,44L 33,57L 27,57L 27,44L 33,44 Z M 19,57L 19,51L 
                                                           25,51L 25,57L 19,57 Z M 57,19L 57,57L 51,57L 51,19L 57,19 Z M 49,27L 49,57L 43,57L 43,27L 
                                                           49,27 Z" 
                                                 Brush="{DynamicResource ButtonTextDisabled}"/>
            </DrawingImage.Drawing>
        </DrawingImage>

        <DrawingImage x:Key="ProductQuantityIcon">
            <DrawingImage.Drawing>
                <GeometryDrawing Geometry="M 38,15.8334L 58.5833,23.75L 58.5833,30.0833L 38,38L 17.4167,30.0833L 17.4166,23.75L 
                                                 38,15.8334 Z M 58.5833,44.3333L 58.5833,52.25L 38,60.1667L 17.4167,52.25L 17.4167,44.3333L 
                                                 21.5333,45.9167L 38,52.25L 54.4667,45.9167L 58.5833,44.3333 Z M 58.5833,33.25L 58.5833,41.1667L 
                                                 38,49.0833L 17.4167,41.1667L 17.4167,33.25L 21.5333,34.8333L 38,41.1667L 54.4666,34.8333L 
                                                 58.5833,33.25 Z" 
                                                 Brush="{DynamicResource ButtonTextDisabled}"/>
            </DrawingImage.Drawing>
        </DrawingImage>

        <DrawingImage x:Key="RequireDpIcon">
            <DrawingImage.Drawing>
                <GeometryDrawing Geometry="M 61.9265,41.022L 53.0007,43.0713C 53.6708,41.0949 53.9557,38.9728 53.7924,36.8188L 
                                                 61.9265,41.022 Z M 52.7817,57.0555L 45.0225,52.1939C 46.9628,51.2366 48.6434,49.9111 50.0017,48.3301L 
                                                 52.7817,57.0555 Z M 34.978,61.9265L 32.9287,53.0007C 34.9051,53.6708 37.0272,53.9557 39.1812,53.7924L 
                                                 34.978,61.9265 Z M 18.9445,52.7817L 23.8061,45.0225C 24.7634,46.9629 26.0889,48.6435 27.6699,50.0017L 
                                                 18.9445,52.7817 Z M 14.0735,34.978L 22.9993,32.9288C 22.3292,34.9052 22.0443,37.0272 22.2076,39.1812L 
                                                 14.0735,34.978 Z M 23.2183,18.9445L 30.9775,23.8062C 29.0371,24.7634 27.3565,26.0889 25.9983,27.6699L 
                                                 23.2183,18.9445 Z M 41.022,14.0735L 43.0712,22.9993C 41.0948,22.3292 38.9728,22.0443 36.8188,22.2076L 
                                                 41.022,14.0735 Z M 57.0555,23.2183L 52.1938,30.9775C 51.2366,29.0371 49.9111,27.3566 48.3301,25.9983L 
                                                 57.0555,23.2183 Z M 38,25.3333C 44.9956,25.3333 50.6667,31.0044 50.6667,38C 50.6667,44.9956 
                                                 4.9956,50.6667 38,50.6667C 31.0044,50.6667 25.3333,44.9956 25.3333,38C 25.3333,31.0044 31.0044,25.3333 
                                                 38,25.3333 Z" 
                                                 Brush="{DynamicResource ButtonTextDisabled}"/>
            </DrawingImage.Drawing>
        </DrawingImage>
        
        <HierarchicalDataTemplate x:Key="StructureTemplate"
                                  ItemsSource="{Binding Path=ChildNodes}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="34"/>
                    <ColumnDefinition Width="20"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="100"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="20"/>
                </Grid.RowDefinitions>
                
                <Image Width="34"
                       Height="34"
                       Grid.RowSpan="2"
                       Stretch="Uniform"
                       VerticalAlignment="Center"
                       Source="{Binding Icon}" />

                <TextBlock Text="{Binding ComponentQuantity }"
                           Grid.Row="0" 
                           Grid.RowSpan="2" 
                           Grid.Column="0"
                           HorizontalAlignment="Right"
                           VerticalAlignment="Bottom"
                           TextAlignment="Center"
                           Panel.ZIndex="2"
                           Width="18"
                           FontSize="11"
                           Margin="0,0,1,4"
                           Background="{DynamicResource Hyperlink}"
                           Foreground="{DynamicResource ButtonTextPressed}"
                           ToolTip="{x:Static resources:Resources.RR_ComponentQuantity}"/>

                <Border Background="{Binding Path=Item[quality], Converter={StaticResource ItemTypeColor}}"
                        Grid.Row="0" 
                        Grid.Column="1"
                        HorizontalAlignment="Right"
                        Width="10"
                        Height="10"
                        Margin="0,0,4,0"
                        Panel.ZIndex="2"/>

                <mui:ModernButton Grid.Row="1" 
                                  Grid.Column="1"
                                  Margin="3,0,0,0"
                                  EllipseDiameter="14"
                                  IconHeight="8"
                                  IconWidth="8"
                                  Tag="{Binding IsApply, Converter={StaticResource BooleanToBit}}"
                                  Command="{Binding ApplyMaterialCommand}"
                                  ToolTip="{x:Static resources:Resources.RR_ApplyMaterial}">
                    <mui:ModernButton.Style>
                        <Style TargetType="mui:ModernButton">
                            <Setter Property="IconData" Value="{StaticResource ApplyIcon}"/>
                            <Style.Triggers>
                                <Trigger Property="Tag" Value="0">
                                    <Setter Property="IconData" Value=""/>
                                </Trigger>
                            </Style.Triggers>

                        </Style>
                    </mui:ModernButton.Style>
                </mui:ModernButton>
                
                <Image Grid.Row="0" 
                       Grid.Column="2"
                       HorizontalAlignment="Left"
                       Width="12"
                       Height="12"
                       Margin="1,0,0,0"
                       Visibility="{Binding IsCriticalCraft, Converter={StaticResource BooleanToVisibilityConverter}}"
                       ToolTip="{x:Static resources:Resources.RR_CriticalCraftItem}">
                    <Image.Source>
                        <DrawingImage>
                            <DrawingImage.Drawing>
                                <GeometryDrawing Geometry="M 38,3.16666C 57.2379,3.16666 72.8333,18.7621 72.8333,38C 72.8333,57.2379 57.2379,72.8333 
                                                 38,72.8333C 18.7621,72.8333 3.16667,57.2379 3.16667,38C 3.16667,18.7621 18.7621,3.16666 38,3.16666 
                                                 Z M 52.252,18.9974L 36.4164,18.9974L 23.75,39.5833L 34.8333,39.5833L 25.3316,60.1667L 50.6667,34.8333L 
                                                 38,34.8333L 52.252,18.9974 Z" 
                                                 Brush="{Binding Path=Item[quality], Converter={StaticResource ItemTypeColor}}"/>
                            </DrawingImage.Drawing>
                        </DrawingImage>
                    </Image.Source>
                </Image>

                <TextBlock Text="{Binding Item[translate] }"
                           FontWeight="DemiBold"
                           Grid.Row="0" 
                           Grid.Column="2"
                           Margin="16,0,0,0"/>

                <Image Grid.Row="1" 
                       Grid.Column="2"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Top"
                       Width="9"
                       Height="9"
                       Margin="15,2,0,0"
                       Visibility="{Binding IsRecipe, Converter={StaticResource BooleanToVisibilityConverter}}"
                       ToolTip="{x:Static resources:Resources.RR_RecipeLevel}"
                       Source="{StaticResource RecipeLevelIcon}"/>
                
                <TextBlock Text="{Binding RecipeLevel }"
                           Grid.Row="1" 
                           Grid.Column="2"
                           FontSize="11"
                           Width="25"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Top"
                           Visibility="{Binding IsRecipe, Converter={StaticResource BooleanToVisibilityConverter}}"
                           ToolTip="{x:Static resources:Resources.RR_RecipeLevel}"
                           Margin="30,0,0,0"/>

                <Image Grid.Row="1" 
                       Grid.Column="2"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Top"
                       Width="9"
                       Height="9"
                       Margin="65,2,0,0"
                       Visibility="{Binding IsRecipe, Converter={StaticResource BooleanToVisibilityConverter}}"
                       ToolTip="{x:Static resources:Resources.RR_ProductQuantity}"
                       Source="{StaticResource ProductQuantityIcon}"/>
                
                <TextBlock Text="{Binding ProductQuantity }"
                           Grid.Row="1" 
                           Grid.Column="2"
                           FontSize="11"
                           Width="15"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Top"
                           Visibility="{Binding IsRecipe, Converter={StaticResource BooleanToVisibilityConverter}}"
                           ToolTip="{x:Static resources:Resources.RR_ProductQuantity}"
                           Margin="80,0,0,0"/>

                <Image Grid.Row="1" 
                       Grid.Column="2"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Top"
                       Width="9"
                       Height="9"
                       Margin="105,2,0,0"
                       Visibility="{Binding IsConvertRecipe, Converter={StaticResource BooleanToVisibilityConverter}}"
                       ToolTip="{x:Static resources:Resources.RR_RequireDP}"
                       Source="{StaticResource RequireDpIcon}"/>

                <TextBlock Text="{Binding RequireDp }"
                           Grid.Row="1" 
                           Grid.Column="2"
                           FontSize="11"
                           Width="35"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Top"
                           Visibility="{Binding IsConvertRecipe, Converter={StaticResource BooleanToVisibilityConverter}}"
                           ToolTip="{x:Static resources:Resources.RR_RequireDP}"
                           Margin="120,0,0,0"/>


                <StackPanel Orientation="Horizontal"
                            Visibility="{Binding IsApply, Mode=OneWay, 
                                                          Converter={StaticResource BooleanToVisibilityConverter}}"
                            Grid.Row="0" 
                            Grid.RowSpan="2"
                            Grid.Column="3"
                            ToolTip="{x:Static resources:Resources.RR_TotalDemandToolTip}">
                    
                    <TextBlock Text="{Binding TotalDemand, 
                                          ConverterCulture='ru-RU',
                                          StringFormat={}{0:N0}}"
                               FontSize="16"
                               VerticalAlignment="Center"
                               Visibility="{Binding IsRecipe, Mode=OneWay, 
                                                              Converter={StaticResource BooleanToVisibilityConverter},
                                                              ConverterParameter=inverse}"/>
                    
                    <TextBlock Text="{Binding TotalDemand, 
                                          ConverterCulture='ru-RU',
                                          StringFormat={}{0:N0}}"
                               FontSize="16"
                               Foreground="{DynamicResource ButtonTextDisabled}"
                               VerticalAlignment="Center"
                               Visibility="{Binding IsRecipe, Mode=OneWay, 
                                                              Converter={StaticResource BooleanToVisibilityConverter}}"/>
                    
                </StackPanel>
                
                
            </Grid>
        </HierarchicalDataTemplate>

        <Style x:Key="MaterialsListViewItem"
               BasedOn="{StaticResource {x:Type ListViewItem}}"
               TargetType="ListViewItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <Grid>
                            <Border Name="Selection" Visibility="Collapsed" />

                            <GridViewRowPresenter HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                                  VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                                                  Content="{TemplateBinding ContentControl.Content}"
                                                  SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />

                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="Selection" Property="Visibility" Value="Visible" />
                                <Setter TargetName="Selection" Property="Background" Value="{DynamicResource ItemBackgroundHover}" />
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextHover}" />
                            </Trigger>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter TargetName="Selection" Property="Visibility" Value="Visible" />
                                <Setter TargetName="Selection" Property="Background" Value="{DynamicResource ItemBackgroundSelected}" />
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextSelected}" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextDisabled}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="true">
                    <Setter Property="Foreground" Value="{DynamicResource ItemTextSelected}" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsExpanded" 
                    Value="{Binding IsExpanded, Mode=TwoWay}" />
            <Setter Property="Visibility" 
                    Value="{Binding IsHidden, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=inverse}"/>
            <Setter Property="Background"
                    Value="Transparent"/>
            <Setter Property="VerticalContentAlignment"
                    Value="{Binding Path=VerticalContentAlignment,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="HorizontalContentAlignment" 
                    Value="Stretch" />
            <Setter Property="HorizontalAlignment" 
                    Value="Stretch" />
            <Setter Property="Padding"
                    Value="4,2"/>
            <Setter Property="Foreground"
                    Value="{DynamicResource ItemText}"/>
            <Setter Property="FocusVisualStyle"
                    Value="{StaticResource TreeViewItemFocusVisual}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeViewItem}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="19"
                                                  Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>

                            <ToggleButton x:Name="Expander"
                                          Style="{StaticResource ExpandCollapseToggleStyle}"
                                          IsChecked="{Binding Path=IsExpanded,RelativeSource={RelativeSource TemplatedParent}}"
                                          ClickMode="Press"/>
                            <Border Name="Bd"
                                    Grid.Column="1"
                                    Grid.ColumnSpan="3"
                                    Opacity="{Binding Opacity}"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}"
                                    SnapsToDevicePixels="true">

                                <ContentPresenter x:Name="PART_Header"
                                                  ContentSource="Header"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </Border>
                            <ItemsPresenter x:Name="ItemsHost"
                                            Grid.Row="1"
                                            Grid.Column="1"
                                            Grid.ColumnSpan="3"/>

                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsExpanded" Value="false">
                                <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed"/>
                            </Trigger>
                            <Trigger Property="HasItems" Value="false">
                                <Setter TargetName="Expander" Property="Visibility" Value="Hidden"/>
                            </Trigger>
                            <Trigger SourceName="Bd" Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="{DynamicResource ItemBackgroundHover}"/>
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextHover}"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter TargetName="Bd" Property="Background" Value="{DynamicResource ItemBackgroundSelected}"/>
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextSelected}"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextDisabled}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="VirtualizingStackPanel.IsVirtualizing"
                         Value="true">
                    <Setter Property="ItemsPanel">
                        <Setter.Value>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel/>
                            </ItemsPanelTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

    </UserControl.Resources>

    <Grid Style="{StaticResource ContentRoot}"
          Visibility="{Binding PageVisible}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="3"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Border Grid.Column="0"
                Grid.ColumnSpan="4"
                BorderThickness="0,0,0,1"
                BorderBrush="{DynamicResource Accent}"
                Margin="0,0,0,6">
            
            <StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Top">
                <Canvas Width="40"
                        Height="40">
                    <Image Width="40"
                           Height="40"
                       Stretch="Uniform"
                       VerticalAlignment="Center"
                       Source="{Binding ProductIcon}" />
                    <Image Width="40"
                       Height="40"
                       Opacity="0.5"
                       Panel.ZIndex="1"
                       Stretch="Uniform"
                       VerticalAlignment="Center"
                       Source="{Binding Combo1Icon}" />
                </Canvas>

                <StackPanel Orientation="Vertical"
                        Margin="10,0,0,0">
                    <Border Background="{Binding Path=ProductQuality, Converter={StaticResource ItemTypeColor}}"
                        HorizontalAlignment="Right"
                        Width="10"
                        Height="10"
                        Margin="0,5,0,12"/>
                    <Border Background="{Binding Path=Combo1Quality, Converter={StaticResource ItemTypeColor}}"
                        HorizontalAlignment="Right"
                        Width="10"
                        Height="10"/>
                </StackPanel>

                <StackPanel Orientation="Vertical"
                            Margin="5,0,0,0">
                    <TextBlock Text="{Binding RootRecipe[p_translate]}"
                           Margin="0,0,0,5"/>
                    <TextBlock Text="{Binding RootRecipe[c1_translate]}"/>
                </StackPanel>

                <StackPanel Orientation="Horizontal"
                            Margin="25,0,0,0">
                    
                    <Image HorizontalAlignment="Left"
                           VerticalAlignment="Top"
                           Width="9"
                           Height="9"
                           Margin="0,5,0,5"
                           ToolTip="{x:Static resources:Resources.RR_RecipeLevel}"
                           Source="{StaticResource RecipeLevelIcon}"/>

                    <TextBlock Text="{Binding RootRecipe[required_skillpoint]}"
                               Margin="10,0,0,5"
                               VerticalAlignment="Top"
                               ToolTip="{x:Static resources:Resources.RR_RecipeLevel}"/>

                    <Image HorizontalAlignment="Left"
                           VerticalAlignment="Top"
                           Width="9"
                           Height="9"
                           Margin="25,5,0,0"
                           ToolTip="{x:Static resources:Resources.RR_ProductQuantity}"
                           Source="{StaticResource ProductQuantityIcon}"/>

                    <TextBlock Text="{Binding RootRecipe[product_quantity]}"
                               Margin="10,0,0,5"
                               VerticalAlignment="Top"
                               ToolTip="{x:Static resources:Resources.RR_ProductQuantity}"/>

                    <Image HorizontalAlignment="Left"
                           VerticalAlignment="Top"
                           Width="9"
                           Height="9"
                           Margin="25,5,0,0"
                           ToolTip="{x:Static resources:Resources.RR_RequireDP}"
                           Source="{StaticResource RequireDpIcon}"/>

                    <TextBlock Text="{Binding RootRecipe[require_dp], TargetNullValue=0 }"
                               Width="35"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Top"
                               ToolTip="{x:Static resources:Resources.RR_RequireDP}"
                               Margin="10,0,0,5"/>

                </StackPanel>

                <StackPanel Orientation="Vertical"
                            HorizontalAlignment="Right"
                            Margin="45,0,0,0">
                    <RadioButton Content="{x:Static resources:Resources.RR_NeedQuantity}" 
                                 IsChecked="{Binding CheckNeedProduct}"/>
                    <RadioButton Content="{x:Static resources:Resources.RR_NeedQuantityCraft}"
                                 IsChecked="{Binding CheckNeedCraft}"/>
                </StackPanel>
                
                <StackPanel Orientation="Horizontal"
                            HorizontalAlignment="Right"
                            Margin="25,0,0,0">

                    <xctk:IntegerUpDown Value="{Binding RequiredQuantity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        Maximum="1000"
                                        Minimum="1"
                                        Margin="5,0,0,0"
                                        Width="50"
                                        Height="20"
                                        TextAlignment="Center"
                                        VerticalAlignment="Center"/>

                    <Slider Margin="5,0,0,0"
                            MaxWidth="300"
                            MinWidth="100"
                            Minimum="1"
                            Maximum="1000"
                            VerticalAlignment="Center"
                            Value="{Binding RequiredQuantity, Mode=TwoWay}"/>
                    
                </StackPanel>
                
            </StackPanel>
        </Border>
        
        <StackPanel Orientation="Vertical"
                    Margin="0,20,0,0"
                    Grid.Column="0"
                    Grid.Row="1"
                    Grid.RowSpan="2">
            <mui:ModernButton IconData="{StaticResource CollapsTree}"
                              Command="{Binding CollapsTreeCommand}"
                              ToolTip="{x:Static resources:Resources.RR_CollapsTree}"/>
            <mui:ModernButton IconData="{StaticResource ExpandTree}"
                              Command="{Binding ExpandTreeCommand}"
                              ToolTip="{x:Static resources:Resources.RR_ExpandTree}"/>

            <mui:ModernButton IconData="{StaticResource HiddenTree}"
                              Command="{Binding HideTreeCommand}"
                              ToolTip="{x:Static resources:Resources.RR_HiddenTree}"
                              Margin="0,20,0,0"/>
            <mui:ModernButton IconData="{StaticResource ShowTree}"
                              Command="{Binding ShowTreeCommand}"
                              ToolTip="{x:Static resources:Resources.RR_Showtree}"/>
            
            <TextBlock Margin="0,5,0,0"
                       TextAlignment="Center"
                       FontSize="10"
                       HorizontalAlignment="Center"
                       Text="{Binding HideTreeCount}"
                       ToolTip="{x:Static resources:Resources.RR_HideTreeText}"/>
            
        </StackPanel>
       

        <TreeView ItemsSource="{Binding TopNodes}"
                  ItemTemplate="{StaticResource StructureTemplate}"
                  Grid.Row="1"
                  Grid.RowSpan="2" 
                  Grid.Column="1"
                  Margin="0,10,20,0"/>

        

        <GridSplitter Grid.Row="1" 
                      Grid.Column="2" 
                      Grid.RowSpan="2"/>
       
        
        <TextBlock Text="{x:Static resources:Resources.RR_SummaryMaterialsNeed}"
                   Background="{DynamicResource ButtonBackgroundHover}"
                   TextAlignment="Left"
                   HorizontalAlignment="Stretch"
                   VerticalAlignment="Top"
                   Margin="2,0,0,0"
                   Grid.Row="1" 
                   Grid.Column="3"/>
        
        <Border Grid.Row="1" 
                Grid.Column="3"
                BorderThickness="0,1,0,0"
                BorderBrush="OrangeRed"
                Margin="2,20,0,0">
            <ListView HorizontalAlignment="Stretch"
                      VerticalAlignment="Stretch"
                      HorizontalContentAlignment="Stretch"
                      VerticalContentAlignment="Stretch"
                      IsSynchronizedWithCurrentItem="True"
                      ItemContainerStyle="{StaticResource MaterialsListViewItem}"
                      ItemsSource="{Binding RequireMaterialsList}"
                      ScrollViewer.HorizontalScrollBarVisibility="Auto"
                      helpers:GridViewSort.AutoSort="True">
                <ListView.View>
                    <GridView>
                        <GridView.Columns>

                            <GridViewColumn Width="Auto"
                                        helpers:GridViewSort.PropertyExtendedName="Value"
                                        helpers:GridViewSort.PropertyName="Key">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Margin="2,2,0,2"
                                               Text="{Binding Path=Key}"
                                               TextWrapping="WrapWithOverflow" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                                <GridViewColumn.Header>
                                    <Path Width="10"
                                          Height="10"
                                          Margin="0"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          Data="{StaticResource MaterialsIcon}"
                                          Fill="{DynamicResource ButtonText}"
                                          RenderTransformOrigin="0.5,0.5"
                                          Stretch="Uniform"/>
                                </GridViewColumn.Header>
                            </GridViewColumn>

                            <GridViewColumn Width="75"
                                        helpers:GridViewSort.PropertyExtendedName="Key"
                                        helpers:GridViewSort.PropertyName="Value">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock HorizontalAlignment="Center" 
                                               Text="{Binding Path=Value, 
                                                              ConverterCulture='ru-RU',
                                                              StringFormat={}{0:N0}}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                                <GridViewColumn.Header>
                                    <Path Width="10"
                                          Height="10"
                                          Margin="0"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          Data="{StaticResource QuantityIcon}"
                                          Fill="{DynamicResource ButtonText}"
                                          RenderTransformOrigin="0.5,0.5"
                                          Stretch="Uniform"/>
                                </GridViewColumn.Header>
                            </GridViewColumn>

                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
        </Border>
        
        
        <TextBlock Text="{x:Static resources:Resources.RR_SummaryMaterialsHave}"
                   Background="{DynamicResource ButtonBackgroundHover}"
                   Grid.Row="2" 
                   Grid.Column="3"
                   Margin="2,20,0,0"
                   TextAlignment="Left"
                   HorizontalAlignment="Stretch"
                   VerticalAlignment="Top"/>

        <Border Grid.Row="2" 
                  Grid.Column="3"
                BorderThickness="0,1,0,0"
                BorderBrush="DarkBlue"
                Margin="2,40,0,0">
            <ListView HorizontalAlignment="Stretch"
                      VerticalAlignment="Stretch"
                      HorizontalContentAlignment="Stretch"
                      VerticalContentAlignment="Stretch"
                      IsSynchronizedWithCurrentItem="True"
                      ItemContainerStyle="{StaticResource MaterialsListViewItem}"
                      ItemsSource="{Binding InStockMaterialsList}"
                      ScrollViewer.HorizontalScrollBarVisibility="Auto"
                      helpers:GridViewSort.AutoSort="True">

                <ListView.View>
                    <GridView>
                        <GridView.Columns>

                            <GridViewColumn Width="Auto"
                                        helpers:GridViewSort.PropertyExtendedName="Value"
                                        helpers:GridViewSort.PropertyName="Key">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Margin="4,4,0,4"
                                               Text="{Binding Path=Key}"
                                               TextWrapping="WrapWithOverflow" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                                <GridViewColumn.Header>
                                    <Path Width="10"
                                          Height="10"
                                          Margin="0"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          Data="{StaticResource MaterialsIcon}"
                                          Fill="{DynamicResource ButtonText}"
                                          RenderTransformOrigin="0.5,0.5"
                                          Stretch="Uniform"/>
                                </GridViewColumn.Header>
                            </GridViewColumn>

                            <GridViewColumn Width="75"
                                        helpers:GridViewSort.PropertyExtendedName="Key"
                                        helpers:GridViewSort.PropertyName="Value">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock HorizontalAlignment="Center" 
                                               Text="{Binding Path=Value, 
                                                              ConverterCulture='ru-RU',
                                                              StringFormat={}{0:N0}}" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                                <GridViewColumn.Header>
                                    <Path Width="10"
                                          Height="10"
                                          Margin="0"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          Data="{StaticResource QuantityIcon}"
                                          Fill="{DynamicResource ButtonText}"
                                          RenderTransformOrigin="0.5,0.5"
                                          Stretch="Uniform"/>
                                </GridViewColumn.Header>
                            </GridViewColumn>

                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
        </Border>
        

    </Grid>
    
</UserControl>
